next up previous contents index
Next: Structured statements Up: Statements Previous: Statements

Simple statements

A simple statement cannot be decomposed in separate statements. There are basically 4 kinds of simple statements:


Simple statements

syntdiag3169

Of these statements, the raise statement will be explained in the chapter on Exceptions (chapter (gif))

Assignments

Assignments give a value to a variable, replacing any previous value the observable might have had:


Assignments

syntdiag3243

In addition to the standard Pascal assignment operator ( := ), which simply replaces the value of the varable with the value resulting from the expression on the right of the := operator, Free Pascal supports some c-style constructions. All available constructs are listed in table (gif).

  

Assignment Result
a += b Adds b to a, and stores the result in a.
a -= b Substracts b from a, and stores the result in a.
a *= b Multiplies a with b, and stores the result in a.
a /= b Divides a through b, and stores the result in a.
Table: Allowed C constructs in Free Pascal

For these constructs to work, you should specify the -Sc command-line switch.

Remark: These constructions are just for typing convenience, they don't generate different code.

Here are some examples of valid assignment statements:
listing3215

Procedure statements

Procedure statements are calls to subroutines. There are different possibilities for procedure calls: A normal procedure call, an object method call (qualified or not) , or even a call to a procedural type variable. All types are present in the following diagram.


Procedure statements

syntdiag3286

The Free Pascal compiler will look for a procedure with the same name as given in the procedure statement, and with a declared parameter list that matches the actual parameter list.

The following are valid procedure statements:
listing3273

Goto statements

Free Pascal supports the goto jump statement. Its prototype syntax is


Goto statement

syntdiag3331

When using goto statements, you must keep the following in mind:

  1. The jump label must be defined in the same block as the Goto statement.
  2. Jumping from outside a loop to the inside of a loop or vice versa can have strange effects.
  3. To be able to use the Goto statement, you need to specify the -Sg compiler switch.
Goto statements are considered bad practice and should be avoided as much as possible. It is always possible to replace a goto statement by a construction that doesn't need a goto, although this construction may not be as clear as a goto statement.

For instance, the following is an allowed goto statement:
listing3313


next up previous contents index
Next: Structured statements Up: Statements Previous: Statements

Michael Van Canneyt
Fri Sep 25 09:15:40 MEST 1998